package com.example.myapplication.found.model;

import com.example.myapplication.found.bean.StockBean;
import com.example.myapplication.found.bean.StockKlineBean;
import com.example.myapplication.found.bean.WeekDayZhangDie;
import com.example.myapplication.found.bean.ZhangDieBean;
import com.example.myapplication.found.contract.FenxiCallback;
import com.example.myapplication.found.contract.ZhangDieCallback;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author: rongfeng
 * @date: 2022/2/25
 * @description 涨跌幅
 */
public class Fenxi2 extends BaseData {

    FenxiCallback fenxiCallback;

    public Fenxi2(StockBean stockBean, StockBean weekStockBean) {
        super(stockBean, weekStockBean);
    }

    public FenxiCallback getFenxiCallback() {
        return fenxiCallback;
    }

    public void setFenxiCallback(FenxiCallback fenxiCallback) {
        this.fenxiCallback = fenxiCallback;
    }

    @Override
    public void start() {
        test1();
    }

    public static int range0, range1, range2, range3, range4, range5, range6, range7, range8, range9, range10, range11;
    public static int _range1, _range2, _range3, _range4, _range5, _range6, _range7, _range8, _range9, _range10, _range11;
    public static String startDate;
    public static int maxSize;
    public static int lineTotal;
    public static int stockTotal;
    public static int tuishiTotal;
    static List<String> codeList = new ArrayList<>();


    //涨跌比例
    private void test1() {
        if (!codeList.contains(fundCode)) {
            codeList.add(fundCode);
        } else {
            if (fenxiCallback != null) {
                fenxiCallback.fenxiCallback(1);
            }
            return;
        }
        if (fundName.startsWith("退市")) {
            tuishiTotal++;
        }
        stockTotal++;
        if (stockBean.klineList.size() > maxSize) {
            maxSize = stockBean.klineList.size();
            startDate = stockBean.klineList.get(0).date;
        }
        for (StockKlineBean stockKlineBean : stockBean.klineList) {
            lineTotal++;
            if (stockKlineBean.chg == 0) {
                range0++;
            } else if (stockKlineBean.chg > 0 && stockKlineBean.chg <= 1) {
                range1++;
            } else if (stockKlineBean.chg > 1 && stockKlineBean.chg <= 2) {
                range2++;
            } else if (stockKlineBean.chg > 2 && stockKlineBean.chg <= 3) {
                range3++;
            } else if (stockKlineBean.chg > 3 && stockKlineBean.chg <= 4) {
                range4++;
            } else if (stockKlineBean.chg > 4 && stockKlineBean.chg <= 5) {
                range5++;
            } else if (stockKlineBean.chg > 5 && stockKlineBean.chg <= 6) {
                range6++;
            } else if (stockKlineBean.chg > 6 && stockKlineBean.chg <= 7) {
                range7++;
            } else if (stockKlineBean.chg > 7 && stockKlineBean.chg <= 8) {
                range8++;
            } else if (stockKlineBean.chg > 8 && stockKlineBean.chg <= 9) {
                range9++;
            } else if (stockKlineBean.chg > 9 && stockKlineBean.chg <= 10) {
                range10++;
            } else if (stockKlineBean.chg > 10) {
                range11++;
            } else if (stockKlineBean.chg < 0 && stockKlineBean.chg > -1) {
                _range1++;
            } else if (stockKlineBean.chg < -1 && stockKlineBean.chg > -2) {
                _range2++;
            } else if (stockKlineBean.chg < -2 && stockKlineBean.chg > -3) {
                _range3++;
            } else if (stockKlineBean.chg < -3 && stockKlineBean.chg > -4) {
                _range4++;
            } else if (stockKlineBean.chg < -4 && stockKlineBean.chg > -5) {
                _range5++;
            } else if (stockKlineBean.chg < -5 && stockKlineBean.chg > -6) {
                _range6++;
            } else if (stockKlineBean.chg < -6 && stockKlineBean.chg > -7) {
                _range7++;
            } else if (stockKlineBean.chg < -7 && stockKlineBean.chg > -8) {
                _range8++;
            } else if (stockKlineBean.chg < -8 && stockKlineBean.chg > -9) {
                _range9++;
            } else if (stockKlineBean.chg < -9 && stockKlineBean.chg > -10) {
                _range10++;
            } else if (stockKlineBean.chg < -10) {
                _range11++;
            }
        }
        if (fenxiCallback != null) {
            fenxiCallback.fenxiCallback(1);
        }
    }


    public static void analysis() {
        System.out.println("A股所有股票涨跌幅度统计");
        System.out.println("退市股票数量：" + Fenxi2.tuishiTotal);
        System.out.println("统计开始日期： " + Fenxi2.startDate + " 截止日期：" + "2022-07-29");
        System.out.println("统计股票数量：" + Fenxi2.stockTotal + " 支");
        System.out.println("总统计次数：" + Fenxi2.lineTotal);
        System.out.println();
        System.out.println("0%：" + range0 + " " + ((float) range0 / lineTotal)*100);
        System.out.println(">10%：" + range11 + " " + ((float) range11 / lineTotal)*100);
        System.out.println("9%~10%：" + range10 + " " + ((float) range10 / lineTotal)*100);
        System.out.println("8%~9%：" + range9 + " " + ((float) range9 / lineTotal)*100);
        System.out.println("7%~8%：" + range8 + " " + ((float) range8 / lineTotal)*100);
        System.out.println("6%~7%：" + range7 + " " + ((float) range7 / lineTotal)*100);
        System.out.println("5%~6%：" + range6 + " " + ((float) range6 / lineTotal)*100);
        System.out.println("4%~5%：" + range5 + " " + ((float) range5 / lineTotal)*100);
        System.out.println("3%~4%：" + range4 + " " + ((float) range4 / lineTotal)*100);
        System.out.println("2%~3%：" + range3 + " " + ((float) range3 / lineTotal)*100);
        System.out.println("1%~2%：" + range2 + " " + ((float) range2 / lineTotal)*100);
        System.out.println("0%~1%：" + range1 + " " + ((float) range1 / lineTotal)*100);
        System.out.println("0%~-1%：" + _range1 + " " + ((float) _range1 / lineTotal)*100);
        System.out.println("-1%~-2%：" + _range2 + " " + ((float) _range2 / lineTotal)*100);
        System.out.println("-2%~-3%：" + _range3 + " " + ((float) _range3 / lineTotal)*100);
        System.out.println("-3%~-4%：" + _range4 + " " + ((float) _range4 / lineTotal)*100);
        System.out.println("-4%~-5%：" + _range5 + " " + ((float) _range5 / lineTotal)*100);
        System.out.println("-5%~-6%：" + _range6 + " " + ((float) _range6 / lineTotal)*100);
        System.out.println("-6%~-7%：" + _range7 + " " + ((float) _range7 / lineTotal)*100);
        System.out.println("-7%~-8%：" + _range8 + " " + ((float) _range8 / lineTotal)*100);
        System.out.println("-8%~-9%：" + _range9 + " " + ((float) _range9 / lineTotal)*100);
        System.out.println("-9%~-10%：" + _range10 + " " + ((float) _range10 / lineTotal)*100);
        System.out.println("<-10%：" + _range11 + " " + ((float) _range11 / lineTotal)*100);
    }


    public static double median(List<Float> total) {
        if (total.size() <= 0) {
            return 0;
        }
        double j = 0;
        //集合排序
        Collections.sort(total);
        int size = total.size();
        if (size % 2 == 1) {
            j = total.get((size - 1) / 2);
        } else {
            //加0.0是为了把int转成double类型，否则除以2会算错
            j = (total.get(size / 2 - 1) + total.get(size / 2) + 0.0) / 2;
        }
        return j;
    }

}
